package cn.edu.pet.servlet.admin;

import cn.edu.pet.entity.Pets;
import cn.edu.pet.entity.User;
import cn.edu.pet.repo.PetRepo;
import cn.edu.pet.repo.UserRepo;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/admin/pet/add")
public class PetAddServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        String intro = req.getParameter("intro");
        String type = req.getParameter("type");
        String image = req.getParameter("image");
        String gender = req.getParameter("gender");
        String status = req.getParameter("status");
        Pets pets = new Pets();
        pets.setName(name);
        pets.setIntro(intro);
        pets.setType(type);
        pets.setImage(image);
        pets.setGender(gender);
        pets.setStatus(status);
        PetRepo.getInstance().insertPets(pets);
        resp.sendRedirect("/admin/pet_index.html");
    }
}
